﻿
namespace bookMaster.AssetSystem.Windows.Forms
{
	/// <summary>
	/// abstract Usuarios typed datagridview
	/// </summary>
	[System.ComponentModel.DesignerCategoryAttribute("code")]
	public abstract class UsuariosDataGridViewBase : System.Windows.Forms.UserControl
	{	
		/// <summary> 
		/// Thrown when the current Entity changed.
		/// </summary>
		public event System.EventHandler<UsuariosDataGridViewEventArgs> CurrentEntityChanged;
		
		#region Fields
				
		/// <summary> 
		/// the current entity.
		/// </summary>
		private Entities.Usuarios _currentUsuarios = null;
		//private Dictionary<string, string> _columnsHeaders = new Dictionary<string, string>();
		
		/// <summary> 
		/// the datagridview instance
		/// </summary>
		protected System.Windows.Forms.DataGridView uxUsuariosDataGridView;
		
		/// <summary> 
		/// the errorprovider
		/// </summary>
		protected System.Windows.Forms.ErrorProvider uxUsuariosErrorProvider;
		
		/// <summary> 
		/// the bindingsource
		/// </summary>
		protected System.Windows.Forms.BindingSource uxUsuariosBindingSource;
		
		
		/// <summary> 
		/// the DGV column associated with the IdUsuario property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxIdUsuarioDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the NombreUsuario property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxNombreUsuarioDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the UsuarioWindows property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxUsuarioWindowsDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Fingerprint property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxFingerprintDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Supervisor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxSupervisorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the ClaveSupervisor property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxClaveSupervisorDataGridViewColumn;
		
		/// <summary> 
		/// the DGV column associated with the Habilitar property
		/// </summary>
		protected System.Windows.Forms.DataGridViewTextBoxColumn uxHabilitarDataGridViewColumn;
		
		#endregion
					
		#region Combo list
		
		#endregion
		
		#region Main Datasource
		
		private Entities.TList<Entities.Usuarios> _UsuariosList;
				
		/// <summary> 
		/// The list of Usuarios to be displayed in the DGV.
		/// </summary>
		[System.ComponentModel.Category("Data")]
		public Entities.TList<Entities.Usuarios> UsuariosList
		{
			get {return this._UsuariosList;}
			set
			{
				this._UsuariosList = value;
				this.uxUsuariosBindingSource.DataSource = null;
				this.uxUsuariosBindingSource.DataSource = value;
				this.uxUsuariosDataGridView.DataSource = null;
				this.uxUsuariosDataGridView.DataSource = this.uxUsuariosBindingSource;				
				//this.uxUsuariosBindingSource.ListChanged += new System.ComponentModel.ListChangedEventHandler(uxUsuariosBindingSource_ListChanged);
				this.uxUsuariosBindingSource.CurrentItemChanged += new System.EventHandler(OnUsuariosBindingSourceCurrentItemChanged);
			}
		}
		
		private void OnUsuariosBindingSourceCurrentItemChanged(object sender, System.EventArgs e)
		{
			_currentUsuarios = uxUsuariosBindingSource.Current as Entities.Usuarios;
			
			if (_currentUsuarios != null)
			{
				_currentUsuarios.Validate();
			}
			//_Usuarios.Validate();
			OnCurrentEntityChanged();
		}

		//void uxUsuariosBindingSource_ListChanged(object sender, System.ComponentModel.ListChangedEventArgs e)
		//{
			//throw new Exception("The method or operation is not implemented.");
		//}		
		
		#endregion
		
		/// <summary>
		/// Gets the currently selected <c cref="Entities.Usuarios"/> instance.
		/// </summary>
		public Entities.Usuarios SelectedUsuarios
		{
			get {return this._currentUsuarios;}
		}
		
		#region other properties
		
		/// <summary>
		/// Gets or sets a value indicating whether you have provided your own data-management operations for the DataGridView control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool VirtualMode
		{
			get {return this.uxUsuariosDataGridView.VirtualMode;}
			set
			{
				this.uxUsuariosDataGridView.VirtualMode = value;
			}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the option to add rows is displayed to the user.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToAddRows
		{
			get {return this.uxUsuariosDataGridView.AllowUserToAddRows;}
			set {this.uxUsuariosDataGridView.AllowUserToAddRows = value;}
		}
		
		/// <summary>
		/// Gets or sets a value indicating whether the user is allowed to delete rows from the DataGridView.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public bool AllowUserToDeleteRows
		{
			get {return this.uxUsuariosDataGridView.AllowUserToDeleteRows;}
			set {this.uxUsuariosDataGridView.AllowUserToDeleteRows = value;}
		}
		
		/// <summary>
		/// Gets the <c cref="DataGridView"/> instance.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]
		public System.Windows.Forms.DataGridView DataGridView
		{
			get {return this.uxUsuariosDataGridView;}
		}
		
		/// <summary>
		/// Gets a collection that contains all the columns in the control.
		/// </summary>
		[System.ComponentModel.Category(".netTiers")]		
		[System.ComponentModel.DesignerSerializationVisibilityAttribute(System.ComponentModel.DesignerSerializationVisibility.Visible)]
		//[System.ComponentModel.EditorAttribute("System.Windows.Forms.Design.DataGridViewColumnCollectionEditor, System.Design", typeof(System.Drawing.Design.UITypeEditor))] 
		public System.Windows.Forms.DataGridViewColumnCollection Columns
		{
			get { return this.uxUsuariosDataGridView.Columns; }
		}
		
		#endregion
		
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.IContainer components = null;
	
		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
		protected override void Dispose(bool disposing)
		{
			if (disposing && (components != null))
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}
	
		#region Constructor
	
		/// <summary>
		/// Initializes a new instance of the <see cref="UsuariosDataGridViewBase"/> class.
		/// </summary>
		public UsuariosDataGridViewBase()
		{			
			this.components = new System.ComponentModel.Container();			
			
			this.uxUsuariosDataGridView = new System.Windows.Forms.DataGridView();
			this.uxUsuariosBindingSource = new System.Windows.Forms.BindingSource(this.components);
			this.uxUsuariosErrorProvider = new System.Windows.Forms.ErrorProvider(this.components);
			this.uxIdUsuarioDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxNombreUsuarioDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxUsuarioWindowsDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxFingerprintDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxSupervisorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxClaveSupervisorDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			this.uxHabilitarDataGridViewColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
			((System.ComponentModel.ISupportInitialize)(this.uxUsuariosDataGridView)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxUsuariosBindingSource)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.uxUsuariosErrorProvider)).BeginInit();
			this.SuspendLayout();
						
			// 
			// uxUsuariosErrorProvider
			// 
			this.uxUsuariosErrorProvider.ContainerControl = this;
			this.uxUsuariosErrorProvider.DataSource = this.uxUsuariosBindingSource;						
			// 
			// uxUsuariosDataGridView
			// 
			this.uxUsuariosDataGridView.AutoGenerateColumns = false;
			this.uxUsuariosDataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
			this.uxUsuariosDataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
		this.uxIdUsuarioDataGridViewColumn,
		this.uxNombreUsuarioDataGridViewColumn,
		this.uxUsuarioWindowsDataGridViewColumn,
		this.uxFingerprintDataGridViewColumn,
		this.uxSupervisorDataGridViewColumn,
		this.uxClaveSupervisorDataGridViewColumn,
		this.uxHabilitarDataGridViewColumn			});
			this.uxUsuariosDataGridView.Dock = System.Windows.Forms.DockStyle.Fill;
			this.uxUsuariosDataGridView.Location = new System.Drawing.Point(0, 0);
			this.uxUsuariosDataGridView.Name = "uxUsuariosDataGridView";
			this.uxUsuariosDataGridView.Size = new System.Drawing.Size(470, 300);
			this.uxUsuariosDataGridView.TabIndex = 0;	
			this.uxUsuariosDataGridView.BackgroundColor = System.Drawing.Color.WhiteSmoke;
			this.uxUsuariosDataGridView.EnableHeadersVisualStyles = false;
			this.uxUsuariosDataGridView.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.OnUsuariosDataGridViewDataError);
			this.uxUsuariosDataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnUsuariosDataGridViewCellValueNeeded);
			this.uxUsuariosDataGridView.CellValuePushed += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.OnUsuariosDataGridViewCellValuePushed);
			
			//
			// uxIdUsuarioDataGridViewColumn
			//
			this.uxIdUsuarioDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxIdUsuarioDataGridViewColumn.DataPropertyName = "IdUsuario";
			this.uxIdUsuarioDataGridViewColumn.HeaderText = "IdUsuario";
			this.uxIdUsuarioDataGridViewColumn.Name = "uxIdUsuarioDataGridViewColumn";
			this.uxIdUsuarioDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxIdUsuarioDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxIdUsuarioDataGridViewColumn.ReadOnly = false;		
			//
			// uxNombreUsuarioDataGridViewColumn
			//
			this.uxNombreUsuarioDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxNombreUsuarioDataGridViewColumn.DataPropertyName = "NombreUsuario";
			this.uxNombreUsuarioDataGridViewColumn.HeaderText = "NombreUsuario";
			this.uxNombreUsuarioDataGridViewColumn.Name = "uxNombreUsuarioDataGridViewColumn";
			this.uxNombreUsuarioDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxNombreUsuarioDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxNombreUsuarioDataGridViewColumn.ReadOnly = false;		
			//
			// uxUsuarioWindowsDataGridViewColumn
			//
			this.uxUsuarioWindowsDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxUsuarioWindowsDataGridViewColumn.DataPropertyName = "UsuarioWindows";
			this.uxUsuarioWindowsDataGridViewColumn.HeaderText = "UsuarioWindows";
			this.uxUsuarioWindowsDataGridViewColumn.Name = "uxUsuarioWindowsDataGridViewColumn";
			this.uxUsuarioWindowsDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxUsuarioWindowsDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxUsuarioWindowsDataGridViewColumn.ReadOnly = false;		
			//
			// uxFingerprintDataGridViewColumn
			//
			this.uxFingerprintDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxFingerprintDataGridViewColumn.DataPropertyName = "Fingerprint";
			this.uxFingerprintDataGridViewColumn.HeaderText = "Fingerprint";
			this.uxFingerprintDataGridViewColumn.Name = "uxFingerprintDataGridViewColumn";
			this.uxFingerprintDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxFingerprintDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxFingerprintDataGridViewColumn.ReadOnly = false;		
			//
			// uxSupervisorDataGridViewColumn
			//
			this.uxSupervisorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxSupervisorDataGridViewColumn.DataPropertyName = "Supervisor";
			this.uxSupervisorDataGridViewColumn.HeaderText = "Supervisor";
			this.uxSupervisorDataGridViewColumn.Name = "uxSupervisorDataGridViewColumn";
			this.uxSupervisorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxSupervisorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxSupervisorDataGridViewColumn.ReadOnly = false;		
			//
			// uxClaveSupervisorDataGridViewColumn
			//
			this.uxClaveSupervisorDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxClaveSupervisorDataGridViewColumn.DataPropertyName = "ClaveSupervisor";
			this.uxClaveSupervisorDataGridViewColumn.HeaderText = "ClaveSupervisor";
			this.uxClaveSupervisorDataGridViewColumn.Name = "uxClaveSupervisorDataGridViewColumn";
			this.uxClaveSupervisorDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxClaveSupervisorDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxClaveSupervisorDataGridViewColumn.ReadOnly = false;		
			//
			// uxHabilitarDataGridViewColumn
			//
			this.uxHabilitarDataGridViewColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.DisplayedCells;
			this.uxHabilitarDataGridViewColumn.DataPropertyName = "Habilitar";
			this.uxHabilitarDataGridViewColumn.HeaderText = "Habilitar";
			this.uxHabilitarDataGridViewColumn.Name = "uxHabilitarDataGridViewColumn";
			this.uxHabilitarDataGridViewColumn.Resizable = System.Windows.Forms.DataGridViewTriState.True;
			this.uxHabilitarDataGridViewColumn.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
			this.uxHabilitarDataGridViewColumn.ReadOnly = false;		
			
			// this
			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			this.Controls.Add(this.uxUsuariosDataGridView);
			this.Name = "UsuariosDataGridView";
			this.Size = new System.Drawing.Size(470, 300);
			((System.ComponentModel.ISupportInitialize)(this.uxUsuariosErrorProvider)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxUsuariosDataGridView)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.uxUsuariosBindingSource)).EndInit();
			this.ResumeLayout(false);
		}
		#endregion
				
		#region events
		
		/// <summary>
		/// Raised the CurrentEntityChanged event.
		/// </summary>
		protected void OnCurrentEntityChanged()
		{
			if (CurrentEntityChanged != null)
			{
				UsuariosDataGridViewEventArgs args = new UsuariosDataGridViewEventArgs();
				args.Usuarios = _currentUsuarios;
				CurrentEntityChanged(this, args); 
			}
		}
		
		#endregion
		
		/// <summary>
		/// Strongly typed event 
		/// </summary>
		public class UsuariosDataGridViewEventArgs : System.EventArgs
		{
			private Entities.Usuarios	_Usuarios;
	
			/// <summary>
			/// the  Entities.Usuarios instance.
			/// </summary>
			public Entities.Usuarios Usuarios
			{
				get { return _Usuarios; }
				set { _Usuarios = value; }
			}	
		}
		
		/// <summary>
		/// Handles the DataError event of the uxUsuariosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewDataErrorEventArgs"/> instance containing the event data.</param>
		protected void OnUsuariosDataGridViewDataError(object sender, System.Windows.Forms.DataGridViewDataErrorEventArgs e)
		{
			System.Diagnostics.Debug.WriteLine(string.Format( "{0}, {1}", e.ColumnIndex, e.RowIndex));
		}
		
		/// <summary>
		/// Handles the CellValueNeeded event of the uxUsuariosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnUsuariosDataGridViewCellValueNeeded(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxUsuariosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdUsuarioDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].IdUsuario;
						break;
					case "uxNombreUsuarioDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].NombreUsuario;
						break;
					case "uxUsuarioWindowsDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].UsuarioWindows;
						break;
					case "uxFingerprintDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].Fingerprint;
						break;
					case "uxSupervisorDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].Supervisor;
						break;
					case "uxClaveSupervisorDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].ClaveSupervisor;
						break;
					case "uxHabilitarDataGridViewColumn":
						e.Value = UsuariosList[e.RowIndex].Habilitar;
						break;
				default:
				break;
			}
		}
		
		/// <summary>
		/// Handles the CellValuePushed event of the uxUsuariosDataGridView control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.Windows.Forms.DataGridViewCellValueEventArgs"/> instance containing the event data.</param>
		protected void OnUsuariosDataGridViewCellValuePushed(object sender, System.Windows.Forms.DataGridViewCellValueEventArgs e)
		{
			switch(uxUsuariosDataGridView.Columns[e.ColumnIndex].Name)
			{
					case "uxIdUsuarioDataGridViewColumn":
						UsuariosList[e.RowIndex].IdUsuario = (string)e.Value;
						break;
					case "uxNombreUsuarioDataGridViewColumn":
						UsuariosList[e.RowIndex].NombreUsuario = (string)e.Value;
						break;
					case "uxUsuarioWindowsDataGridViewColumn":
						UsuariosList[e.RowIndex].UsuarioWindows = (short)e.Value;
						break;
					case "uxFingerprintDataGridViewColumn":
						UsuariosList[e.RowIndex].Fingerprint = (string)e.Value;
						break;
					case "uxSupervisorDataGridViewColumn":
						UsuariosList[e.RowIndex].Supervisor = (System.Int16?)e.Value;
						break;
					case "uxClaveSupervisorDataGridViewColumn":
						UsuariosList[e.RowIndex].ClaveSupervisor = (string)e.Value;
						break;
					case "uxHabilitarDataGridViewColumn":
						UsuariosList[e.RowIndex].Habilitar = (short)e.Value;
						break;
				default:
				break;
			}
		}
	}
}
